﻿/*
=======================================================
    Stock【库存信息】
=======================================================
*/

namespace Services
{
    public interface IStockRepository : IRepository<Stock>
    {
    }


    public class StockRepository : BaseRepository<Stock>, IStockRepository
    {
        public StockRepository(ISqlSugarClient dB, ICurrentUser currentUser, IQuery<Stock> query)
            : base(dB, currentUser, query)
        {
        }

        #region GetPage
        public override (List<Stock> items, int totalCount) GetPage(Expressionable<Stock> where, int pageIndex = 1, int pageSize = 20, string orderBy = null)
        {
            var fs = _DB.Queryable<Stock, Department>
                 ((x, d) => new JoinQueryInfos(
                      JoinType.Left, x.DepartmentID == d.DepartmentID
                    ))
                    .Select((x, d) => new Stock
                    {
                        StockID = x.StockID.SelectAll(),
                        Department_Name = d.Name
                    });

            return _query.GetPage(where, pageIndex, pageSize, orderBy, fs);
        }
        #endregion

        #region GetModel
        public override Stock GetModel(Expressionable<Stock> where, string orderBy = null)
        {
            var fs = _DB.Queryable<Stock, Department>
                  ((x, d) => new JoinQueryInfos(
                       JoinType.Left, x.DepartmentID == d.DepartmentID
                     ))
                     .Select((x, d) => new Stock
                     {
                         StockID = x.StockID.SelectAll(),
                         Department_Name = d.Name
                     });

            return _query.GetModel(where, orderBy, fs);
        }
        #endregion

        #region GetSearch
        public override List<Stock> GetSearch(Expressionable<Stock> where, string orderBy = null, int? top = null)
        {
            var fs = _DB.Queryable<Stock, Department>
                 ((x, d) => new JoinQueryInfos(
                      JoinType.Left, x.DepartmentID == d.DepartmentID
                    ))
                    .Select((x, d) => new Stock
                    {
                        StockID = x.StockID.SelectAll(),
                        Department_Name = d.Name
                    });

            return _query.GetSearch(where, orderBy, top, fs);
        } 
        #endregion
    }
}
